package com.yitiao.data_algorithms.leetcode.editor.cn;

class LongestSubarrayOf1sAfterDeletingOneElement {
    // 2022-11-07 18:23:24
    public static void main(String[] args) {
        Solution solution = new LongestSubarrayOf1sAfterDeletingOneElement().new Solution();
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int longestSubarray(int[] nums) {
            int left = 0;
            int right = 0;
            int count[] = new int[2];
            while (right < nums.length) {
                count[nums[right]]++;
                if (count[0] > 1) {
                    if (nums[left] == 0) {
                        count[0]--;
                    } else {
                        count[1]--;
                    }
                    left++;
                }
                right++;
            }

            if ((right - left) == 0) return 0;
            return right - left - 1;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}